package com.ksd.modules.download.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ksd.common.annotation.ApiLog;
import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.common.po.BatchIdsPO;
import com.ksd.common.web.annotation.RepeatSubmit;
import com.ksd.modules.download.po.AdminDownloadsSavePO;
import com.ksd.modules.download.po.AdminDownloadsSearchPO;
import com.ksd.modules.download.service.IAdminDownloadsService;
import com.ksd.modules.download.vo.AdminDownloadsVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
public class AdminDownloadsController extends BaseController {
    
    @Autowired
    private IAdminDownloadsService adminDownloadsService;

    /**
     * 【下载资源】- 列表
     * @return
     */
    @PostMapping("/download/list")
    public R<Page<AdminDownloadsVo>> findAdminDownloadss(@Validated @RequestBody AdminDownloadsSearchPO adminDownloadsSearchPO){
        return R.data(adminDownloadsService.findAdminDownloadss(adminDownloadsSearchPO));
    }

    /**
     * 【下载资源】- 回收站
     * @return
     */
    @PostMapping("/download/recyle")
    public R<Page<AdminDownloadsVo>> findAdminDownloadssRecyle(@Validated @RequestBody AdminDownloadsSearchPO adminDownloadsSearchPO){
        return R.data(adminDownloadsService.findAdminDownloadssRecyle(adminDownloadsSearchPO));
    }

    /**
     * 【下载资源】 - 保存和更新
     * @param adminDownloadsSavePO
     * @return
     */
    @PostMapping("/download/saveupdate")
    @ApiLog("【下载资源】 - 保存和更新")
    @RepeatSubmit
    public R<AdminDownloadsVo> saveUpdateAdminDownloads(@Validated @RequestBody AdminDownloadsSavePO adminDownloadsSavePO){
        return R.data(adminDownloadsService.saveUpdateAdminDownloads(adminDownloadsSavePO));
    }

    /**
     * 【下载资源】 - 根据id查询明细
     * @param id
     * @return
     */
    @PostMapping("/download/get/{id}")
    public R<AdminDownloadsVo> getAdminDownloadsById(@PathVariable("id")Long id){
        return R.data(adminDownloadsService.getAdminDownloadsById(id));
    }

    /**
     * 【下载资源】 - 根据id删除下载资源
     * @param id
     * @return
     */
    @PostMapping("/download/del/{id}")
    @ApiLog("【下载资源】 - 根据id删除下载资源 ")
    public R<Boolean> deleteAdminDownloadsById(@PathVariable("id")Long id){
        return R.data(adminDownloadsService.deleteAdminDownloadsById(id));
    }

    /**
     * 【下载资源】- 根据id恢复删除
     *
     * @param id
     * @return
     */
    @PostMapping("/download/recover/{id}")
    @ApiLog("【下载资源】- 根据id恢复删除")
    @RepeatSubmit
    public R<Boolean> recoverByIdAdminDownloads(@PathVariable("id") Long id) {
        return R.data(adminDownloadsService.recoverByIdAdminDownloads(id));
    }

    /**
     * 【下载资源】- 批量逻辑删除
     *
     * @return
     */
    @PostMapping("/download/batch/dels")
    @ApiLog("【下载资源】- 批量逻辑删除")
    @RepeatSubmit
    public R<Boolean> bacthDeletesAdminDownloads(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminDownloadsService.bacthDeletesAdminDownloads(batchIdsPO));
    }


    /**
     * 【下载资源】- 批量恢复
     *
     * @return
     */
    @PostMapping("/download/batch/recover")
    @ApiLog("【下载资源】- 批量恢复")
    @RepeatSubmit
    public R<Boolean> batchRecoversAdminDownloads(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminDownloadsService.batchRecoversAdminDownloads(batchIdsPO));
    }
    
    /**
     * 【下载资源】- 批量物理删除
     *
     * @return
     */
    @PostMapping("/download/batch/remove")
    @ApiLog("【下载资源】- 批量物理删除")
    @RepeatSubmit
    public R<Boolean> batchRemovesAdminDownloads(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminDownloadsService.batchRemovesAdminDownloads(batchIdsPO));
    }

    /**
     * 【下载资源】- 根据ID恢复删除
     * @param id
     * @return
     */
    @PostMapping("/download/remove/{id}")
    @ApiLog("【下载资源】- 根据ID恢复删除")
    public R<Boolean> removeAdminDownloadsById(@PathVariable("id")Long id){
        return R.data(adminDownloadsService.removeAdminDownloadsById(id));
    }

    /**
     * 【下载资源】- 修改状态
     *
     * @return
     */
    @PostMapping("/download/status/{id}/{field}")
    @ApiLog("【下载资源】- 修改状态")
    @RepeatSubmit
    public R<Boolean> updateStatus(
            @PathVariable("id") Long id,
            @PathVariable("field") String field,
            @RequestParam("value") String value
    ) {
        if(StringUtils.isNumeric(value)) {
            return R.data(adminDownloadsService.updateStatus(id, field, Integer.parseInt(value)));
        }else{
            return R.data(adminDownloadsService.updateStatusStr(id, field, String.valueOf(value)));
        }
    }

    /**
     * 【下载】-批量上架
     *
     * @return
     */
    @PostMapping("/download/batch/up")
    @ApiLog("【下载】-批量上架")
    @RepeatSubmit
    public R<Boolean> batchUps(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminDownloadsService.batchUps(batchIdsPO));
    }

    /**
     * 【下载】-批量下架
     *
     * @return
     */
    @PostMapping("/download/batch/down")
    @ApiLog("【下载】-批量下架")
    @RepeatSubmit
    public R<Boolean> batchDowns(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminDownloadsService.batchDowns(batchIdsPO));
    }

    /**
     * 【下载】- 复制数据
     * @param opid
     * @return
     */
    @PostMapping("/download/copy/{opid}")
    @ApiLog("【下载】- 复制数据")
    @RepeatSubmit
    public R<Boolean> copyData(@PathVariable("opid")Long opid){
        return R.data(adminDownloadsService.copyData(opid));
    }
}
